/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.spakehelpdesk.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author leehoanh
 */
@Entity
@Table(name = "Account", catalog = "HelpDesk", schema = "dbo")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Account.sortwithDepart", query = "SELECT a FROM Department d, IN (d.accountList) a ORDER BY d.departmentID DESC"),
    @NamedQuery(name = "Account.findforLogin", query = "SELECT a FROM Account a WHERE a.accountID = :accountID and a.password = :password and a.status = True"),
    @NamedQuery(name = "Account.findByName", query = "SELECT a FROM Account a WHERE a.fullName LIKE :fullName and a.status = True"),
    @NamedQuery(name = "Account.findByRole", query = "SELECT a FROM Role r, IN (r.accountList) a WHERE r.roleID = :roleID"),
    @NamedQuery(name = "Account.findByDepartment", query = "SELECT a FROM Department d, IN (d.accountList) a WHERE d.departmentID = :departmentID"),
    @NamedQuery(name = "Account.findAll", query = "SELECT a FROM Account a"),
    @NamedQuery(name = "Account.findAllAccLock", query = "SELECT a FROM Account a WHERE a.status = False"),
    @NamedQuery(name = "Account.findByAccountID", query = "SELECT a FROM Account a WHERE a.accountID = :accountID"),
    @NamedQuery(name = "Account.findByFullName", query = "SELECT a FROM Account a WHERE a.fullName = :fullName"),
    @NamedQuery(name = "Account.findByPassword", query = "SELECT a FROM Account a WHERE a.password = :password"),
    @NamedQuery(name = "Account.findByTelephoneNumber", query = "SELECT a FROM Account a WHERE a.telephoneNumber = :telephoneNumber"),
    @NamedQuery(name = "Account.findByEmail", query = "SELECT a FROM Account a WHERE a.email = :email"),
    @NamedQuery(name = "Account.findByStatus", query = "SELECT a FROM Account a WHERE a.status = :status")})
public class Account implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "AccountID", nullable = false, length = 20)
    private String accountID;
    @Size(max = 50)
    @Column(name = "FullName", length = 50)
    private String fullName;
    @Size(max = 50)
    @Column(name = "Password", length = 50)
    private String password;
    @Size(max = 20)
    @Column(name = "TelephoneNumber", length = 20)
    private String telephoneNumber;
    // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
    @Size(max = 50)
    @Column(name = "Email", length = 50)
    private String email;
    @Column(name = "Status")
    private Boolean status;
    @JoinColumn(name = "RoleID", referencedColumnName = "RoleID")
    @ManyToOne
    private Role roleID;
    @JoinColumn(name = "DepartmentID", referencedColumnName = "DepartmentID")
    @ManyToOne
    private Department departmentID;
    @OneToMany(mappedBy = "accountID")
    private List<Complaint> complaintList;
    @OneToMany(mappedBy = "technicianID")
    private List<Complaint> complaintList1;

    public Account() {
    }

    public Account(String accountID) {
        this.accountID = accountID;
    }

    public String getAccountID() {
        return accountID;
    }

    public void setAccountID(String accountID) {
        this.accountID = accountID;
    }

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getTelephoneNumber() {
        return telephoneNumber;
    }

    public void setTelephoneNumber(String telephoneNumber) {
        this.telephoneNumber = telephoneNumber;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Boolean getStatus() {
        return status;
    }

    public void setStatus(Boolean status) {
        this.status = status;
    }

    public Role getRoleID() {
        return roleID;
    }

    public void setRoleID(Role roleID) {
        this.roleID = roleID;
    }

    public Department getDepartmentID() {
        return departmentID;
    }

    public void setDepartmentID(Department departmentID) {
        this.departmentID = departmentID;
    }

    @XmlTransient
    public List<Complaint> getComplaintList() {
        return complaintList;
    }

    public void setComplaintList(List<Complaint> complaintList) {
        this.complaintList = complaintList;
    }

    @XmlTransient
    public List<Complaint> getComplaintList1() {
        return complaintList1;
    }

    public void setComplaintList1(List<Complaint> complaintList1) {
        this.complaintList1 = complaintList1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (accountID != null ? accountID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Account)) {
            return false;
        }
        Account other = (Account) object;
        if ((this.accountID == null && other.accountID != null) || (this.accountID != null && !this.accountID.equals(other.accountID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.spakehelpdesk.entity.Account[ accountID=" + accountID + " ]";
    }
    
}
